package com.hjduan.spring.cloud.request.service;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * Created by fangzhipeng on 2017/4/6.
 */
@Service
public class RibbonService {

    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod="selfException")
    public City getCityService(Integer id) {
        System.out.println("enter!!!!!!!!!!!!!!!!!!");
        ResponseEntity<City> re = restTemplate.getForEntity("http://MYBATIS-SERVICE/cities/view/"+id, City.class);
    	City city = re.getBody();
    	return city;
    }
    
    
    public String addCityService() {
    	
    	ResponseEntity<String> re = restTemplate.getForEntity("http://MYBATIS-SERVICE/cities/save/aa", String.class);
    	return re.getBody();
    }

    public City selfException(Integer id){
        System.out.println("There is a exception===="+id);
        return null;
    }
}
